<!-- HTML header for doxygen 1.8.3.1-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<title>Nordic Thingy:52 v2.2.0 : OTA-DFU - Generating your own packages</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="extra_stylesheet_offline.css" rel="stylesheet" type="text/css"/>
<link href="nordic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0" width="100%" class="blank">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Nordic Semiconductor" src="nordic_small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">Nordic Thingy:52 v2.2.0
   </div>
  </td>
 </tr>
 </tbody>
</table>
<script>
var url=window.location.href.split("/").reverse()[1];
var validLinks= ["nrf5","s130","s132","s212","s332"];
var index;
for (index = 0; index < validLinks.length; ++index) {
   if ( url.indexOf(validLinks[index]) !== -1 ) {
      document.getElementById(validLinks[index]).setAttribute('class', 'doclinks docselected');
   };
};
</script>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('dfu_generating.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">OTA-DFU - Generating your own packages </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>The following procedures assume that you are working with your own custom firmware. You will need to do the following to generate your own packages:</p>
<ol type="1">
<li>Generate your own public and private key pair.</li>
<li>Generate a custom bootloader.</li>
<li>Generate custom bootloader settings.</li>
</ol>
<p>To run these tasks, you will require <a href="https://github.com/NordicSemiconductor/pc-nrfutil" target="blank">nrfutil</a>.</p>
<h1><a class="anchor" id="dfu_custom_key"></a>
Replacing the public key</h1>
<p>Before you can generate DFU packages, you must first generate new keys. Cryptographic keys are required to sign and validate a Device Firmware Update package. Before running your own custom DFU, you must generate your own private-public key pair.</p>
<p>To generate a new private key, run the following command with nrfutil installed: </p><div class="fragment"><div class="line">nrfutil keys generate <span class="keyword">private</span>-key.pem</div></div><!-- fragment --><p>Make sure you keep this key secret. The command generates the new key file in the folder where you ran the command.</p>
<p>Now, generate a public key from the private one: </p><div class="fragment"><div class="line">nrfutil keys display --key pk --format code <span class="keyword">private</span>-key.pem --out_file dfu_public_key.c</div></div><!-- fragment --><p>Copy the public_key.c from where you generated it to <code>&lt;InstallFolder&gt;\project\bootloader_secure\dfu_public_key.c</code>.</p>
<h1><a class="anchor" id="dfu_custom_bootloader"></a>
Generating the bootloader</h1>
<p>To generate a new bootloader, compile the <code>Bootloader</code> project using either Keil μVision or GCC. Flash the compiled bootloader onto Thingy. Remember to flash the SoftDevice as well for the OTA-DFU to function properly.</p>
<h1><a class="anchor" id="dfu_generate_package"></a>
Generating a DFU package</h1>
<p>Run <code>nrfutil pkg generate</code> to generate a ZIP file that you can later use with a mobile or desktop application to update the Thingy firmware, as described in <a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.tools/dita/tools/nrfutil/nrfutil_pkg.html" target="blank">nrfutil documentation</a>. For example: </p><div class="fragment"><div class="line">nrfutil pkg generate --application &lt;path_to_hex_file&gt; --application-version 0 --hw-version 52 --sd-req 0x98 --key-file <span class="keyword">private</span>-key.pem dfu-app.zip</div></div><!-- fragment --><h2><a class="anchor" id="dfu_version"></a>
Version requirements</h2>
<p>This command contains essential information about the versions of the application and of the hardware. These versions determine whether it will be possible to perform a valid DFU process. DFU is only possible if:</p><ul>
<li>The application version is greater than or equal to the previous application version. <dl class="section note"><dt>Note</dt><dd>If an existing app is replaced with a new one with a higher version number, Thingy will reinitialize parts of its flash storage, and BLE configurable settings will revert to default.</dd></dl>
</li>
<li>The hw-version property is the same as in the previous version.</li>
<li>The bootloader version is greater than the previous bootloader version (bootloader version is provided when you update the bootloader).</li>
</ul>
<h1><a class="anchor" id="dfu_assembly"></a>
Manual firmware assembly</h1>
<p>A firmware package which supports OTA-DFU must consist of the following four elements:</p><ul>
<li>Application</li>
<li>SoftDevice</li>
<li>Bootloader</li>
<li>Bootloader settings</li>
</ul>
<h2><a class="anchor" id="dfu_bootloader_settings"></a>
Bootloader settings</h2>
<p>Bootloader settings is a special area in the bootloader that contains information about the DFU process, as well as information about the versions of the application and the bootloader. You must generate your own bootloader settings file for your custom application. See <a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.tools/dita/tools/nrfutil/nrfutil_settings_generate_display.html" target="blank">nrfutil documentation</a> for information on how to generate the bootloader settings file. Refer to <a class="el" href="dfu_generating.html#dfu_version">Version requirements</a> and make sure that you set correct versions when generating the bootloader settings file.</p>
<h1><a class="anchor" id="dfu_perform_after_gen"></a>
Running a DFU with a custom package</h1>
<p>When your custom package is ready, follow the procedure in <a class="el" href="dfu_connect.html">OTA-DFU with nRF Connect</a> to run an OTA-DFU. </p>
</div></div><!-- contents -->
</div><!-- doc-content -->
<div id="nav-path" class="topicfooter">
<a href="mailto:docfeedback@nordicsemi.no?subject=Documentation%20feedback" id="maillink">Documentation feedback</a> | <a href="https://devzone.nordicsemi.com/questions/" target="_blank">Developer Zone</a> | <a href="http://response.nordicsemi.com/subscribe-to-our-newsletters" target="_blank">Subscribe</a> | Updated <span id="date"/>
<script>
var date = new Date("Thu Feb 7 2019" + " UTC");
document.getElementById("date").innerHTML = date.toJSON().slice(0, 10);
var url=window.location.href.split("?")[0];
var filename=url.substring(url.lastIndexOf('/')+1);
document.getElementById("maillink").href = "mailto:docfeedback@nordicsemi.no?subject=Documentation%20feedback"+decodeURIComponent("%26")+"body=File%20name%3A%20"+encodeURIComponent(filename);
</script>
</div>
</body>
</html>
